<?php

namespace IDock\Insurance\HBIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Printer\PremiumUnderwritingPrinter;
use IDock\Printer\ProposalStatusPrinter;

class InsuranceOrderQueryResponse extends AllHBICResponse
{
    public function printerInit(): Response
    {
        $proposalStatusPrinter = new ProposalStatusPrinter();
        $data = $this->getBody();
        $result = $data['BODY'] ?? [];
        $proposalStatusPrinter->statusCode = 'U4';
        if($this->getError()){
            $proposalStatusPrinter->messageTip = $this->getError();
            $this->printer = $proposalStatusPrinter;
            return $this;
        }
        $underwriteInd = $result['baseInfo']['underWriteInd'] ?? '7';
        if(in_array($underwriteInd,['1','3','5'])){
            $proposalStatusPrinter->statusCode = 'U1';//核保通过
        }else if($underwriteInd == '2' or $underwriteInd == '0'){
            $proposalStatusPrinter->statusCode = 'U2';//退回修改
            $proposalStatusPrinter->messageTip = '退回修改';
        }else if($underwriteInd == '4'){
            $proposalStatusPrinter->statusCode = 'U6';//拒保
        }else if($underwriteInd == '6'){
            $proposalStatusPrinter->statusCode = 'U5';//已出保单
        }else if($underwriteInd == '8' or $underwriteInd == '9'){
            $proposalStatusPrinter->statusCode = 'U3';//待审核
        }else if($underwriteInd == '7'){
            $proposalStatusPrinter->statusCode = 'U4';//复核失败
        }
        $proposalStatusPrinter->inquiryNo = $result['baseInfo']['ProposalNo'] ?? '';
        $proposalStatusPrinter->ciInquiryNo = $result['baseInfo']['efcProposalNo'] ?? '';
        $proposalStatusPrinter->biInquiryNo = $result['baseInfo']['bizProposalNo'] ?? '';
        if($result['forceRiskInfo'] ?? ''){
            $proposalStatusPrinter->ciStartData = $result['forceRiskInfo']['startDate'] ?? '';
            $proposalStatusPrinter->ciEndData = $result['forceRiskInfo']['endDate'] ?? '';
        }
        if($result['businessRiskInfo'] ?? ''){
            $proposalStatusPrinter->biStartData = $result['businessRiskInfo']['startDate'] ?? '';
            $proposalStatusPrinter->biEndData = $result['businessRiskInfo']['endDate'] ?? '';
        }
        $proposalStatusPrinter->status = IDockEnums::$underStats[$proposalStatusPrinter->statusCode] ?? '';
        $this->printer = $proposalStatusPrinter;
        return $this;
    }
}